/*
 *	SNiFF+ Parser Interface
 *  Copyright (C) 1998 TakeFive Software GmbH
 *
 *	Author:		Peter Bucsi
 *	Created:	5. May 95
 *	Version:	1.0  (26. May 98)
 *
 *	This file contains declarations of functions and data types
 *	needed to build a new parser for SNiFF+.
 */
#ifndef _Parser_Interface_h_
#define _Parser_Interface_h_

#if defined(__GNUG__) && __GNUG__ >= 2
#  pragma interface
#endif

#ifndef TRUE
#define TRUE	1
#endif
#ifndef FALSE
#define FALSE	0
#endif

typedef	unsigned char	pi_bool;
typedef int	pi_id;
	
/*
 *	This structure describes a compile job.
 */
typedef struct pi_job_struct
{
	char	*source_file_name;		/* full pathname of the source file to be parsed */
	pi_bool	cpp_on;					/* preprocessor switch (see project attributes) */
	char	*cpp_define;			/* preprocessor defines (see project attributes) */
	char	*cpp_include;			/* preprocessor includes (see project attributes) */
	char	*cpp_filedir;			/* SNiFF+ internal usage */
	char	*parser_config_file;	/* full pathname of the parser configuration file */
	char	*generate_dir;			/* SNiFF+ internal usage */
	pi_bool	no_generate;			/* SNiFF+ internal usage */
	pi_bool generate_only;			/* SNiFF+ internal usage */
	pi_bool bUseXRefDB;				/* SNiFF+ internal usage */
} pi_job;

/*
 *
 */
typedef struct pi_data_struct
{
	int		from;			/* offset relative to begin of file */	
	int		to;				/* offset relative to begin of file */
	int		from2;			/* offset relative to begin of file */	
	int		to2;			/* offset relative to begin of file */
	int		argstart;		/* offset of start of arguments 	*/
	int 	argend;			/* offset of end of arguments 		*/
	int		ctorstart;		/* start of constructor init list	*/
	int 	ctorend;		/* end of constructor init list		*/
	char	*name;			/* see semantic actions for details */
	char	*type;			/* see semantic actions for details */
	char	*classname;		/* see semantic actions for details */
	char	*nameSpace;		/* used for crossref, holds scope/namespace/package */
	int		flags;			/* see semantic actions for details */
	pi_id	related;		/* !!! NOT USED in this version !!! */
} pi_data;

/*
 *	Flags used in pi_data.flags
 */
#define		PI_BIT(n)		(1 << (n))
#define		PI_VIRTUAL		PI_BIT(0)	/* virtual function */
#define		PI_ABSTRACT 		PI_BIT(1)	/* pure virtual function */
#define		PI_INLINE		PI_BIT(2)	/* inline function */
#define		PI_CONST		PI_BIT(3)	/* const variable or function */
#define		PI_PRIVATE		PI_BIT(4)	/* private member access or inheritance */
#define		PI_PUBLIC		PI_BIT(5)	/* public member access or inheritance */
#define		PI_PROTECTED 		PI_BIT(6)	/* protected member access or inheritance */
#define		PI_TEMPLATE 		PI_BIT(7)	/* template class */
#define		PI_FRIEND		PI_BIT(8)	/* friend class or function */
#define		PI_STATIC		PI_BIT(9)	/* static variable or function */
#define		PI_DEFAULT_VAL		PI_BIT(10)	/* function parameter has default value */
#define		PI_FUNCTION		PI_BIT(11)	/* function or member function */
#define		PI_VARIABLE		PI_BIT(12)	/* variable or member variable */
#define		PI_MACRO		PI_BIT(13)	/* macro definition */
#define		PI_TYPEDEF		PI_BIT(14)	/* type definition */
#define		PI_ENUM			PI_BIT(15)	/* enumeration type */
#define		PI_ENUM_ITEM		PI_BIT(16)	/* enumeration item */
#define		PI_CLASS		PI_BIT(17)	/* class declaration */
#define		PI_STRUCT		PI_BIT(18)	/* structure declaration */
#define		PI_UNION		PI_BIT(19)	/* union declaration */
#define		PI_DEFINITION		PI_BIT(20)	/* definition of a function or member function */
#define		PI_DECLARATION		PI_BIT(21)	/* declaration of a member function */
#define		PI_READACCESS		PI_BIT(22)	/* read access to a variable or member variable */
#define		PI_WRITEACCESS		PI_BIT(23)	/* write access to a variable or member variable */
#define		PI_STDINCL			PI_BIT(24)  /* if is standart <include>  else "include " */
#define		PI_FINAL			PI_BIT(25)  /* if symbol is final in JAVA */
#define		PI_SYNCHRONIZED		PI_BIT(26)  /* if symbol is synchronized in JAVA */ 
#define		PI_NATIVE			PI_BIT(27)  /* if symbol is native in JAVA */ 
#define		PI_TRANSIENT		PI_BIT(28)  /* if symbol is transient in JAVA */
#define		PI_VOLATILE			PI_BIT(29)  /* if symbol is volatile */

/*
 *	return values of semantic action functions
 */
#define		PI_NOVALUE		-1			/* default return value (void) */
#define		PI_BADID		-2			/* illegal id in pi_data.related */
#define		PI_NOJOB		-3			/* semantic action called without active job */

#ifdef __cplusplus
extern "C" {
#endif
/********************************************************************************/
/*			J O B  C O N T R O L  F U N C T I O N S			*/
/********************************************************************************/
/*
 *	pi_init()
 *
 *	Sets up a connection to SNiFF+. This function must be called
 *	once at parser start up time before all other API function calls.
 *	Parameters:
 *		pi_bool remoteParser:	FALSE - The parser and SNiFF+ are running
 *						on the same machine
 *					TRUE -	The parser is running on a different
 *						machine than SNiFF+, but in the
 *						same network
 *		char *parserId:			A string that identifies the parser to SNiFF+
 *						It must be the basename of the parser executable
 *	Return value:
 *		pi_bool:			FALSE - connection to SNiFF+ successfully setup
 *						TRUE - cannot connect to SNiFF+
 */
pi_bool		pi_init(pi_bool remoteParser, char *parserId);
void		pi_initialize ( pi_job* pJob );
 
/*
 *	pi_getjob()
 *
 *	Get a new compile job. When the parsing of a file is requested
 *	by SNiFF+ this function returns the compile job. It is waiting
 *	until a new parsing request is received from SNiFF+.
 *	Return value:
 *		pi_job:				> NULL - All details of a compile job.
 *							 (see description of struct pi_job)
 *						NULL -	no more compile jobs.
 *							SNiFF+ requests the parser
 *							to exit.
 */
pi_job		*pi_getjob();
/*
 *	pi_endjob()
 *
 *	Terminate a compile job. This function must be called after
 *	parsing a file, e.g. after calling the last semantic action function.
 *	Note: pi_getjob() and pi_endjob() functions must be called
 *	alternately.
 *	Parameter:
 *		pi_job *job:			Pointer to pi_job returned by previous
 *								pi_getjob() call.
 *
 *	Return value:				FALSE - job successfully terminated
 *						TRUE -  error during termination
 *							(SNiFF+/parser internal synchronization
 *							 error. This should not happen!)
 *														
 */
pi_bool		pi_endjob(pi_job *job);
/*
 *	pi_terminate()
 *
 *	Close connection to SNiFF+. This function must be called
 *	before exiting the parser.
 *	Return Value:
 *		pi_bool:				FALSE - connection successfully closed
 *							TRUE -  error when closing connection
 *								(SNiFF+/parser internal synchronization
 *								 error. This should not happen!)
 */
pi_bool		pi_terminate();
void 		pi_openjob( pi_job* pJob );
void 		pi_closejob( pi_job* pJob );
 
void		pi_set_filename ( pi_job* pJob, char* cpFileName );
void		pi_set_includes ( pi_job* pJob, char* cpIncludes );
void		pi_set_generate ( pi_job* pJob, char* cpGenerate );

/****************************************************************************************/
/*			S E M A N T I C   A C T I O N S 				*/
/****************************************************************************************/
/*	NOTE: All functions return PI_NOVALUE in this version.   */
/*		  pi_data.related is not used in this version.	 */
/*
 *	Comment
 *
 *		pi_data.from:		start comment
 *		pi_data.to:		end comment
 *		pi_data.related:	UNUSED (future use: bind comment to any object)
 */
pi_id		pi_comment(pi_data *);
/*
 *	Macro definition
 *
 *		pi_data.from:		start macro name
 *		pi_data.to:		end macro name
 *		pi_data.name:		macro name
 *		pi_data.type:		macro value
 */
pi_id		pi_macro(pi_data *);
/*
 *	Include statement
 *
 *		pi_data.name:		name of the file exclusive "" or <> delimiters
 *		pi_data.type:		full path and name of include-file or NULL
 *		pi_data.from:		start of <> or "" include statement
 *		pi_data.to:			end of <> or "" include statement
 *		pi_data.flags:		PI_STDINCL
 */
pi_id		pi_include(pi_data *);

/*
 *	Start class definition
 *
 *		pi_data.from:		start class name
 *		pi_data.to:		end class name
 *		pi_data.name:		class name
 *		pi_data.flags:		{PI_CLASS|PI_STRUCT|PI_UNION}, PI_TEMPLATE, PI_FRIEND
 *		pi_data.related:	pi_id of class where this class is nested in
 *					default: previous class not terminated
 */
pi_id		pi_start_class(pi_data *);	
/*
 *	End class definition (terminate class definition)
 *
 *		pi_data.from:		start position of the whole class declaration
 *		pi_data.to:		end position of the whole class declaration
 *		pi_data.related:	pi_id of class to be terminated
 *					default: previous class not terminated
 */
pi_id		pi_end_class(pi_data *);	
/*
 *	Base class specifier
 *
 *		pi_data.from:		start base class name
 *		pi_data.to:			end base class name
 *		pi_data.name:		base class name optionally including preceeding   
 *							scope specifiers seperated by "?"
 *		pi_data.flags:		{PI_PUBLIC|PI_PROTECTED|PI_PRIVATE}, PI_VIRTUAL 
 *							 PI_FINAL
 *		pi_data.related:	pi_id of class having this base class
 *					default: previous class not terminated
 *
 *	NOTE:	The function pi_base() must be called immediately after
 *		calling pi_start_class()
 */
pi_id		pi_base(pi_data *);	
/*
 *	Enumerator
 *
 *		pi_data.from:		start enumerator name
 *		pi_data.to:		end enumerator name
 *		pi_data.name:		enumerator name
 *		pi_data.flags:		{PI_PUBLIC|PI_PROTECTED|PI_PRIVATE}, PI_STATIC
 *		pi_data.related:	pi_id of class including the enumerator as member
 *					default: previous class not terminated or global
 *						 scope if no not terminated class found
 */
pi_id		pi_enum(pi_data *);	
/*
 *	Enumerator item
 *
 *		pi_data.from:		start enumerator item name
 *		pi_data.to:		end enumerator item name
 *		pi_data.name:		enumerator item name
 *		pi_data.related:	pi_id of enumerator containing this item
 *					default: previous enumerator
 *
 *	NOTE:	The function pi_enum_item() must be called immediately after
 *			calling pi_enum()
 */
pi_id		pi_enum_item(pi_data *);	
/*
 *	Variable or member variable declaration
 *
 *		pi_data.from:		start variable name
 *		pi_data.to:		end variable name
 *		pi_data.name:		variable name
 *		pi_data.flags:		{PI_PUBLIC|PI_PROTECTED|PI_PRIVATE}, PI_STATIC, PI_CONST
 *		pi_data.type:		variable type
 *		pi_data.related:	pi_id of class including the variable as member
 *					default: previous class not terminated or global
 *					scope if no not terminated class found
 *
 *	NOTE:	The declared variable is a member variable
 *		if the function pi_variable() is called inside
 *		a class declaration (between pi_start_class()
 *		and pi_end_class()).
 */
pi_id		pi_variable(pi_data *);	
/*
 *	Function declaration/definition
 *
 *		pi_data.from:		start function name (inclusive class name if member function)
 *		pi_data.to:			end function name
 *		pi_data.from2:		start function implementation if inline
 *		pi_data.to2:		end function implementation in inline
 *		pi_data.name:		function name (exclusive class name)
 *		pi_data.argstart:	start of argument list with "("
 *		pi_data.argend:		end of argument list with ")"
 *		pi_data.ctorstart:	start of constructor init list
 *		pi_data.ctorend:	end of constructor init list
 *		pi_data.flags:		{PI_DECLARATION|PI_DEFINITION},
 *					{PI_PUBLIC|PI_PROTECTED|PI_PRIVATE},
 *					PI_STATIC, PI_INLINE, PI_VIRTUAL,
 *					PI_CONST, PI_TEMPLATE, PI_FRIEND, PI_ABSTRACT
 *					PI_TRANSIENT, PI_FINAL, PI_VOLATILE
 *		pi_data.type:		return type
 *		pi_data.classname:	class name if member function (required only if PI_DEFINITION is set)
 *		pi_data.related:	pi_id of class including the function as member
 *					default: previous class not terminated or global
 *						 scope if no not terminated class found
 *
 *	NOTE:	The declared function is a member function
 *		if the function pi_function() is called inside
 *		a class declaration (between pi_start_class()
 *		and pi_end_class()) and PI_DECLARATION is set.
 *		If PI_DEFINITION is set then pi_data.classname
 *		specifies the container class. If pi_data.classname
 *		is not set and PI_DEFINITION is set then a global
 *		function definition is assumed.
 */
pi_id		pi_function(pi_data *);	
/*
 *	Type definition
 *
 *		pi_data.from:		start typedef name
 *		pi_data.to:		end typedef name
 *		pi_data.name:		typedef name
 *		pi_data.flags:		{PI_PUBLIC|PI_PROTECTED|PI_PRIVATE}
 *							PI_SYNCHRONIZED PI_NATIVE, PI_FINAL
 *		pi_data.type:		type definition
 *		pi_data.related:	pi_id of class including the typedef as member
 *					default: previous class not terminated or global
 *						 scope if no not terminated class found
 *
 *	NOTE:	The defined type is valid in a class scope
 *		if the function pi_typedef() is called inside
 *		a class declaration. (between pi_start_class()
 *		and pi_end_class())
 */
pi_id		pi_typedef(pi_data *);
/*
 *	Function parameter
 *
 *		pi_data.from:		start parameter name
 *		pi_data.to:		end parameter name
 *		pi_data.name:		parameter name
 *		pi_data.flags:		PI_DEFAULT_VAL
 *		pi_data.type:		parameter type
 *		pi_data.related:	pi_id of function definition/declaration or reference
 *					default: previous function definition/declaration or reference
 *
 *	NOTE:	pi_data.related is not used in this version!
 *		The call of pi_function() must immediately followed by calls
 *		of pi_parameter(). The functions pi_comment(), pi_error_msg()
 *		and pi_reset() are the only exceptions enabled to call
 *		between pi_function() and pi_parameter() calls.
 *		This function can also be used to specify the actual parameter
 *		list of a function reference (see pi_reference() below).
 */
pi_id		pi_parameter(pi_data *);
/*
 *	Userdefined Symbol:
 *
 *		pi_data.from:		start symbol name
 *		pi_data.to:			end symbol name
 *		pi_data.name:		symbol name
 *		pi_data.type:		type is string with name of new type
 *		pi_data.related:	not supported!
 *					
 *
 *	NOTE:	pi_data.related is not used in this version!
 *		
 *		This Symbol is useful for creating new entries in 			
 *		the SNiFF+ SymTab, only used for beeing highlited		
 *		in the Editor, and showen in the Symbol-Browser !
 *		It must not be called inside a Class scope, only 
 *		in File scope !
 */
pi_id		pi_userdef	(pi_data *);

/*	
 *	Template argument
 *
 *		pi_data.from:		start argument name
 *		pi_data.to:		end argument name
 *		pi_data.name:		argument name
 *		pi_data.related:	pi_id of class definition or function definition/
 *					declaration or parameter having this template argument
 *					default: previous class definition or function
 *						 definition/declaration or parameter
 *
 *	NOTE: This function is not implemented in this version of the API.
 */
pi_id		pi_template_argument(pi_data *);


/*
 *	Symbol reference.
 *
 *		This function must be called whenever a function refers to a symbol.
 *		(e.g. function call, variable access, macro usage,...)
 *		The references are used by the Cross Referencer tool.
 *		The flags PI_READACCESS and PI_WRITEACCESS must be set if
 *		the referred symbol is a variable (PI_VARIABLE).
 *
 *		pi_data.from:		start position of the symbol reference relative to the
 *					pi_data.from position of the related (previous)
 *					pi_function() call.
 *		pi_data.name:		name of the symbol referred
 *		pi_data.classname:	class name if the symbol is class member
 *		pi_data.flags:		{PI_FUNCTION|PI_VARIABLE|PI_MACRO|PI_TYPEDEF|
 *					 PI_ENUM|PI_ENUM_ITEM|PI_CONST}, PI_READACCESS, PI_WRITEACCESS
 *		pi_data.related:	pi_id of function definition or declaration referring to the symbol
 *					default: previous function definition/declaration
 *
 *	NOTE:	The function pi_reference() must be called immediately after
 *		the function definition. The function definition consists of
 *		one call to pi_function() optionally followed by pi_parameter()
 *		calls.
 *		In case of a function reference (PI_FUNCTION is set) the
 *		actual parameter list must be specified. This can be done
 *		by calling pi_parameter() immediately after calling
 *		pi_reference().
 *			
 */
pi_id		pi_reference(pi_data *);

 
/****************************************************************************************/
/*					U T I L I T I E S 				*/
/****************************************************************************************/
/*
 *	Initialize the pi_data structure. This function has to be called
 *	before setting data members of the pi_data structure.
 *	The function does *NOT* free memory pointed by the members on pi_data,
 *	but the pointers will be set to NULL.
 */
void		pi_reset(pi_data *);
/*
 *	Send an error message to SNiFF+. The messages appear in
 *	the log window after calling pi_endjob().
 *	The sequence @B in the message toggles boldface printing.
 */
pi_bool		pi_error_msg(char *);
 
char *pi_project_data_request(int);
 
char *system_RemExecutableExt(char *name);
char *system_BaseName(char *name);
 
pi_bool pi_edg_init (pi_bool tcp, char *parserId);
pi_bool pi_edg_terminate();
pi_bool pi_edg_getjob (pi_job* pJob );
pi_bool pi_edg_endjob(pi_job *job);
 
#ifdef __cplusplus
}
#endif

#endif /* _Parser_Interface_h_ */
 
